#!/usr/bin/env python
#coding=utf-8

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import json

def send_sms(phone_number,code):
    ACCESSKEYID = 'LTAI4G3CWrAGTe2q5TSeDVGE'
    ACCESSSECRET = 'pdnKAXl9pezEeQZrAChr3pCvHHJyVs'
    client = AcsClient(ACCESSKEYID, ACCESSSECRET, 'cn-hangzhou')

    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    sign_name = '小饭桌官网'
    template_code = 'SMS_201650850'
    template_param = json.dumps({"code":code})

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', phone_number)
    request.add_query_param('SignName', sign_name)
    request.add_query_param('TemplateCode', template_code)
    request.add_query_param('TemplateParam', template_param)

    response = client.do_action(request)

    return str(response)